//
//  UIScrollView+ScrollView.m
//  FMS
//
//  Created by Steven on 10/31/13.
//  Copyright (c) 2013 QGSVN. All rights reserved.
//

#import "UIScrollView+ScrollView.h"
#import "LoadingMoreFooterView.h"

#define LoadingViewTag 10000

@implementation UIScrollView (ScrollView)

- (void)showLoadingMore{
    
    LoadingMoreFooterView *loadFooterView = (LoadingMoreFooterView*)[self viewWithTag:LoadingViewTag];
    if (loadFooterView == nil) {
        for (LoadingMoreFooterView *sub in self.subviews) {
            if ([sub isKindOfClass:[LoadingMoreFooterView class]]) {
                loadFooterView = (LoadingMoreFooterView *)sub;
                break;
            }
        }
    }
    if (loadFooterView == nil) {
        loadFooterView = [[LoadingMoreFooterView alloc]initWithFrame:CGRectMake(0, 0, self.self.frame.size.width, 44.0)];
        loadFooterView.tag = LoadingViewTag;
        [self addSubview:loadFooterView];
    }

    loadFooterView.hidden = NO;
    CGPoint contentSize = CGPointMake(self.contentSize.width,self.contentSize.height);
    loadFooterView.frame = CGRectMake(0, contentSize.y, self.frame.size.width, 44);
        
}

- (void)showActivity{
    LoadingMoreFooterView *loadFooterView = (LoadingMoreFooterView*)[self viewWithTag:LoadingViewTag];
    if (loadFooterView == nil) {
        for (LoadingMoreFooterView *sub in self.subviews) {
            if ([sub isKindOfClass:[LoadingMoreFooterView class]]) {
                loadFooterView = (LoadingMoreFooterView *)sub;
                break;
            }
        }
    }
    if (loadFooterView == nil) {
        loadFooterView = [[LoadingMoreFooterView alloc]initWithFrame:CGRectMake(0, 0, self.self.frame.size.width, 44.0)];
        loadFooterView.tag = LoadingViewTag;
        [self addSubview:loadFooterView];
    }
    else;
    
    loadFooterView.hidden = NO;
    loadFooterView.showActivityIndicator = YES;
    CGPoint contentSize = CGPointMake(self.contentSize.width,self.contentSize.height);
    loadFooterView.frame = CGRectMake(0, contentSize.y, self.frame.size.width, 44);
}

- (void)hideActivity{
    LoadingMoreFooterView *loadFooterView = (LoadingMoreFooterView*)[self viewWithTag:LoadingViewTag];
    if (loadFooterView == nil)
        ;
    else
        loadFooterView.showActivityIndicator = NO;
}
- (void)hideLoadingMore{
    LoadingMoreFooterView *loadFooterView = (LoadingMoreFooterView*)[self viewWithTag:LoadingViewTag];
    if (loadFooterView == nil)
        ;
    else
        loadFooterView.hidden = YES;
}
@end
